//
//  ZqlBaseNavVC.swift
//  ZqlSinaWeiBo
//
//  Created by 赵乾龙 on 16/2/24.
//  Copyright © 2016年 Mr.zhao. All rights reserved.
//

import UIKit

class ZqlBaseNavVC: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
       self.interactivePopGestureRecognizer?.delegate = self
    }
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        //获取子视图的数量
        let childCount = childViewControllers.count
        if childCount != 0{
            viewController.hidesBottomBarWhenPushed = true 
         let btn = UIButton(backImageName: nil, title: "返回", textColor: UIColor.darkGrayColor(), imageName: "navigationbar_back_withtext", fontSize: 14)
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
            btn.addTarget(self, action: "clickBack", forControlEvents: .TouchUpInside)
        }
        super.pushViewController(viewController, animated: animated)
    }
    
    @objc private func clickBack(){
        self.popViewControllerAnimated(true)
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        return childViewControllers.count > 1
    }
    
}
